// __PUBLIC__/js/page/admin/usercomplain/usercomplainlist
require(['../../common'], function() {
  require(['usercomplain.usercomplainlist'])
})

define('usercomplain.usercomplainlist', [
  'jquery',
  'page/grid'
], function($, Grid) {
  'use strict';

  var $table = $('.table')
  var mygrid = new Grid($table)
  mygrid.init()

  function getSelected() {
    var selected = mygrid.getSelected()
    if (!selected.count) {
      alert(lang.pleaseSelectAData)
      return
    }
    return selected
  }

  function getASelected(t) {
    var current = mygrid.getCurrent(t)
    var selected = {
      id: [current.id],
      index: [current.index]
    }
    return selected
  }
  $(document)
    .on('click', '.A_del', function(e) {
      e.preventDefault()
      deleteusercomplainFile(getASelected(this))
    })
    .on('click', '#J_del', function(e) {
    	alert('tewfda');
      e.preventDefault()
      deleteusercomplainFile(getSelected())
    })
    .on('click', '#J_search', function(e) {
      e.preventDefault()
      sureSearchusercomplain()
    })

  function deleteusercomplainFile(selected) {
    $.post(APP + '?app=admin&m=UserComplain&a=deleteUserComplain', {
      ids: selected.id.join(),
      withfile: 1
    }).done(function(res) {
      if (res == '1') {
        alert(lang.delSuccess)
        mygrid.del(selected.index)
      } else {
        alert(lang.delFails)
      }
    })
  }

  function sureSearchusercomplain() {
    var userid   = $('#userid').val()
    var touserid = $('#touserid').val()
    var tomsg    = $('#tomsg').val()
    var str_get  =  '&userid=' + userid + '&touserid=' + touserid + '&tomsg=' + tomsg 
    location.href = APP + '?app=admin&m=UserComplain&a=usercomplainlist' + str_get
  }

})
